package com.boyon.system.action;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.boyon.hbm.criteria.OperationType;
import com.boyon.hbm.criteria.Param;
import com.boyon.hbm.criteria.Query;
import com.boyon.system.entity.Config;
import com.boyon.system.service.ConfigService;
import com.boyon.web.param.annotation.ValidatorRequestBody;
import com.boyon.web.response.PageResponse;
import com.boyon.web.response.SuccessResponse;

/**
 * ClassName:ConfigAction <br/>
 * Function: 系统配置信息. <br/>
 * Date: 2018年3月14日 下午10:30:58 <br/>
 * 
 * @author sunshulin
 * @version
 * @since JDK 1.8
 * @see
 */
@Controller
@RequestMapping(value = "/boyon/config", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class ConfigAction {

	@Autowired
	private ConfigService configService;

	/**
	 * 
	 * modifyConfig:修改系统设置信息. <br/>
	 * 
	 * @author sunshulin
	 * @param config
	 * @return
	 * @since JDK 1.8
	 */
	@RequestMapping(value = "/modify")
	@ResponseBody
	public SuccessResponse modifyConfig(@ValidatorRequestBody Config config) {
		configService.modifyConfig(config);
		return new SuccessResponse();
	}

	/**
	 * 
	 * find:配置key查找. <br/>
	 * 
	 * @author sunshulin
	 * @param config
	 * @return
	 * @since JDK 1.8
	 */
	@RequestMapping(value = "/find")
	@ResponseBody
	public SuccessResponse find(@ValidatorRequestBody Config config) {
		return new SuccessResponse(
				configService.findByConfigId(config.getConfigId()));
	}

	/**
	 * 
	 * query:角色列表查询. <br/>
	 * 
	 * @author sunshulin
	 * @param account
	 * @return
	 * @since JDK 1.8
	 */
	@RequestMapping(value = "/query")
	@ResponseBody
	public PageResponse query(@ValidatorRequestBody Config config,
			HttpSession session) {
		Query query = new Query(config.page());
		query.addParam(new Param<String>("configName", OperationType.like,
				config.getConfigName()));
		query.addParam(new Param<String>("configKey", OperationType.like,
				config.getConfigKey()));
		return new PageResponse(configService.query(query), query.getTotal());
	}
}
